package codetop.huawei.T518;

/**
 * @Author: 18362
 * @Create: 2022-09-12 23:33:44 星期一
 */
class Solution {
    public int change(int amount, int[] coins) {
        int[] dp = new int[amount+1], temp = new int[amount+1];
        dp[0] = temp[0] = 1;
        for (int i = 0; i < coins.length; i++) {
            for (int j = 1; j <= amount; j++) {
                int k = 1;
                while (j >= k * coins[i]) {
                    temp[j] += dp[j - k * coins[i]];
                    k++;
                }
            }
            System.arraycopy(temp, 0, dp, 0, dp.length);
        }
        return dp[amount];
    }
}